#include "ADC_HAL_QG.h"

void vfnADC_ResolutionSelect (uint8 u8res)
{
    ADCCFG_MODE = u8res;
}

void vfnADC_LowPowerMode (void) 
{
    ADCCFG_ADLPC = 1;
}

void vfnADC_HighSpeedMode (void) 
{
    ADCCFG_ADLPC = 0;
}

void vfnADC_ClockDivideSelect (uint8 u8ADC_ClockDivider)
{
    ADCCFG_ADIV = u8ADC_ClockDivider;
}

void vfnADC_SetSampleTime (uint8 u8ADC_SampleTime)
{
    ADCCFG_ADLSMP = u8ADC_SampleTime;    
}

void vfnADC_ChannelSelect (uint8 u8channel) 
{
	ADCSC1_ADCH = (u8channel & 0x1F);
}

uint16 u16ADC_GetResult (void)
{	
    return ADCR;
}

uint8 u8ADC_GetResult (void)
{
    return ADCRL;
}

void vfnADC_UseBusClock (void)
{
    ADCCFG_ADICLK = 0;
}

void vfnADC_PinEnable (uint8 u8pin) 
{
    if(u8pin > 7)  // If selected pin is out of range, return   
    { 
        return;
    }
    else
    {
        APCTL1 |= (1<<u8pin);
    }  
}

void vfnADC_PinDisable (uint8 u8pin) 
{
    if(u8pin > 7)  // If selected pin is out of range, return   
    {
        return;
    }
    else
    {
        APCTL1 &= ~(1<<u8pin);
    }
}
          
uint8 u8ADC_CheckCCF (void) 
{
    return ADCSC1_COCO;
}

void vfnADC_InterruptSetup (uint8 u8mode) 
{
    ADCSC1_AIEN = u8mode;     
}

void vfnADC_ConversionMode (uint8 u8mode) 
{
    ADCSC1_ADCO = u8mode;  
}


